cmake_minimum_required(VERSION 2.8)

project(power)

aux_source_directory(. MAIN)

# 将子目录添加, 会执行子目录的CMakeLists.txt
add_subdirectory(math)

add_executable(power ${MAIN})

# 将可执行文件与powerlib进行链接
target_link_libraries(power powerlib)

# 指定安装路径
install (TARGETS power DESTINATION bin)
install (FILES "${PROJECT_BINARY_DIR}/config.h"
         DESTINATION include)
# install
# *.o => /usr/local/bin
# *.h => /usr/local/include


# test
# 启用测试
enable_testing()

# 测试程序是否成功运行
add_test (test_run power 5 2)

# 测试帮助信息是否可以正常提示
add_test (test_usage power)
set_tests_properties (test_usage
  PROPERTIES PASS_REGULAR_EXPRESSION "Usage: .* base exponent")

# 测试 5 的平方
add_test (test_5_2 power 5 2)

set_tests_properties (test_5_2
 PROPERTIES PASS_REGULAR_EXPRESSION "is 25")

# 测试 10 的 5 次方
add_test (test_10_5 power 10 5)

set_tests_properties (test_10_5
 PROPERTIES PASS_REGULAR_EXPRESSION "is 100000")

# 测试 2 的 10 次方
add_test (test_2_10 power 2 10)

set_tests_properties (test_2_10
 PROPERTIES PASS_REGULAR_EXPRESSION "is 1024")

# 定义一个宏，用来简化测试工作
macro (do_test arg1 arg2 result)
  add_test (test_${arg1}_${arg2} power ${arg1} ${arg2})
  set_tests_properties (test_${arg1}_${arg2}
    PROPERTIES PASS_REGULAR_EXPRESSION ${result})
endmacro (do_test)
 
# 使用该宏进行一系列的数据测试
do_test (5 2 "is 25")
do_test (10 5 "is 100000")
do_test (2 10 "is 1024")